<?  layout("../layout/default.html") { ?>
<link rel="stylesheet" href="${root}/Static/js/ztree/css/zTreeStyle/zTreeStyle.css"  type="text/css">
<script type="text/javascript" src="${root}/Static/js/ztree/js/jquery.ztree.all-3.5.min.js"></script>
<div class="admin-panel">
	<div class="panel">
		<div class="panel-head">
			<h3 class="float-left dialogs-delegate">
				<b>资源管理</b> <a href="javascript:;" data-toggle="click" data-title="添加子栏目" data-width="800px" data-height="450px" data-mask="1" data-url="${root}/Resource/create/0"
					class="button  button-little bg-blue  icon-plus dialogx"> 添加分组</a> 
					<a href="${root}/Resource/refresh" class="button  button-little bg-blue  icon-refresh" data-place="right"  title="若有资源更新，必须更新该缓存，否则可能导致权限无法生效"> 更新权限路径缓存</a>
			</h3>
			<div class="toolbar"></div>
			<div class="clearfix"></div>
		</div>
		<div class="panel">
			<div id="treex" class="ztree dialogs-delegate"></div>
		</div>

	</div>
</div>
<script type="text/javascript">
	var IDMark_Switch = "_switch",
	IDMark_Icon = "_ico",
	IDMark_Span = "_span",
	IDMark_Input = "_input",
	IDMark_Check = "_check",
	IDMark_Edit = "_edit",
	IDMark_Remove = "_remove",
	IDMark_Ul = "_ul",
	IDMark_A = "_a";
	var setting = {
		async : {
			enable : true,
			url : "${root}/Resource/getlist",
			autoParam : ["id"],
			type : "get"
		},
		view: {
			addHoverDom: addHoverDom,
			removeHoverDom: removeHoverDom,
			nameIsHTML: true
		}
	};
	var delNode= function(id){
		var treeObj = $.fn.zTree.getZTreeObj('treex');
		var node = treeObj.getNodeByParam("id", id, null);
		if(node==null) return;
		if(node.isParent) {alert("当前节点还有子节点，无法删除！");return;}
		if(!confirm("确定删除？")) return;	
		$.post('${root}/Resource/delete/'+ id, function(json){
			if (json.success) {
					treeObj.removeNode(node);
			}else{
				alert('删除失败');
			}
		},'JSON');
	}
	function addHoverDom(treeId, treeNode) {
		if (treeNode.parentNode && treeNode.parentNode.id!=1) return;
		if ($("#ext_"+treeNode.id).length>0) return;
		var aObj = $("#" + treeNode.tId + IDMark_A);
		Str = '<span id="ext_'+treeNode.id+'" class="tree_btns">';
		Str +='<span  class="margin-small icon-plus text-blue dialogx" data-toggle="click" data-title="添加子栏目" data-width="800px" data-height="450px" data-mask="1" data-url="${root}/Resource/create/'+treeNode.id+'"></span>';
		Str +='<span  class="margin-small icon-edit text-blue dialogx" data-toggle="click" data-title="编辑" data-width="800px" data-height="450px" data-mask="1" data-url="${root}/Resource/update/'+treeNode.id+'"></span>';
		Str +='<span  class="margin-small icon-trash-o text-blue" onclick="javascript:delNode('+treeNode.id+')"></span>';
		Str +='</span>';
		aObj.append(Str);
	}
	function removeHoverDom(treeId, treeNode) {
		//if (treeNode.parentTId && treeNode.getParentNode().id!=1) return;
		$("#ext_"+treeNode.id).unbind().remove();
		$("#ext_" +treeNode.id).unbind().remove();
	}
	$(function() {
		$.fn.zTree.init($("#treex"), setting);
	});
</script>
<?  } ?>

